package com.jerome.rmi;

import com.jerome.rmi.constants.RmiConstant;
import com.jerome.rmi.util.RegistryUtil;

import java.rmi.registry.Registry;

/**
 * CalculatorServer
 * @author jerome
 * @date 2023/7/28
 */
public class CalculatorServer {
    /**
     * start service
     * @author jerome
     * @date 2023/7/29 13:41
     */
    public static void startService(){
        try {
            RemoteDefault remoteUtil = new RemoteDefaultImplementation();
            Registry registry = RegistryUtil.getRegistry();
            //Register default service
            registry.rebind(RmiConstant.DEFAULT_SERVER_NAME, remoteUtil);
            System.out.println("RMI server is ready.");
        } catch (Exception e) {
            System.err.println("RMI server exception: " + e.toString());
            e.printStackTrace();
        }
    }
    /**
     * server main method
     * @param args main method parameters
     * @author jerome
     * @date 2023/7/29 13:43
     */
    public static void main(String[] args) throws InterruptedException {
        //start service
        startService();
    }
}
